package cn.tedu._03vehicle.base.interceptors;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import java.time.LocalDateTime;

/*
  限定访问时间的拦截器：只能在6到22点之间访问
 */
@Slf4j
public class TimeAccessInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.debug("进入限定访问时间拦截器");
        LocalDateTime now = LocalDateTime.now();
        int hour = now.getHour();
        if (hour <6 || hour > 22) {
            throw new  RuntimeException("只能在6到22访问");
        }
            return true;
    }




}
